from rest_framework import serializers
from .models import OrderRating, CommentAuditLog

class CommentSubmitSerializer(serializers.Serializer):
    """评论提交序列化器（支持图片上传到七牛云）"""
    order_id = serializers.IntegerField(help_text="订单ID")
    passenger_id = serializers.IntegerField(help_text="乘客ID")
    driver_id = serializers.IntegerField(help_text="司机ID")
    rating = serializers.IntegerField(min_value=1, max_value=5, help_text="评分(1-5)")
    comment = serializers.CharField(max_length=500, required=False, allow_blank=True, help_text="评论内容")
    image = serializers.ImageField(required=False, help_text="评论图片（可选）")

class CommentAuditLogSerializer(serializers.ModelSerializer):
    """评论审核日志序列化器"""
    class Meta:
        model = CommentAuditLog
        fields = '__all__'

class DriverCommentListSerializer(serializers.ModelSerializer):
    """司机评论列表序列化器"""
    order_number = serializers.CharField(source='order.order_number', read_only=True)
    passenger_name = serializers.SerializerMethodField()
    has_image = serializers.SerializerMethodField()
    
    class Meta:
        model = OrderRating
        fields = [
            'id', 'order_id', 'order_number', 'passenger_id', 'passenger_name',
            'rating', 'comment', 'image_url', 'rating_time', 'audit_status', 'audit_time',
            'audit_result', 'is_sensitive', 'has_image'
        ]
    
    def get_passenger_name(self, obj):
        """获取乘客姓名（这里需要根据实际的用户模型来实现）"""
        return f"乘客{obj.passenger_id}"
    
    def get_has_image(self, obj):
        """检查是否有图片"""
        return bool(obj.image_url)

class CommentAuditStatusSerializer(serializers.Serializer):
    """评论审核状态序列化器"""
    comment_id = serializers.CharField(help_text="评论ID")
    audit_status = serializers.IntegerField(help_text="审核状态(0-待审核,1-通过,2-拒绝)")
    audit_result = serializers.CharField(required=False, help_text="审核结果说明")
    sensitive_words = serializers.ListField(
        child=serializers.CharField(),
        required=False,
        help_text="敏感词列表"
    )
    text_audit = serializers.DictField(required=False, help_text="文本审核结果")
    image_audit = serializers.DictField(required=False, help_text="图片审核结果")

class AuditTaskStatusSerializer(serializers.Serializer):
    """审核任务状态序列化器"""
    pending_count = serializers.IntegerField(help_text="待审核任务数量")
    worker_status = serializers.CharField(help_text="工作器状态")
    last_processed_time = serializers.DateTimeField(required=False, help_text="最后处理时间") 